<template>
  <div>
    <common-head title="编辑联系人"/>
    <div class="wrap">
      <van-address-edit
        :area-list="area"
        :address-info="addressInfo"
        show-postal
        show-delete
        show-set-default
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        @delete="onDelete"
      />
    </div>
  </div>
</template>

<script>
import CommonHead from '@components/CommonHead'
import area from '@utils/area'
import { Toast } from 'vant'
export default {
  data () {
    return {
      area,
      addressInfo: {
      }
    }
  },
  created () {
    this.initAdrressInfo()
  },
  methods: {
    initAdrressInfo () {
      this.addressInfo = this.$store.state.contact.contacts[parseInt(this.$route.query.index)]
    },
    onSave (contact) {
      // 点击保存联系人
      console.log(contact)
      this.$store.commit('contact/update_contact', { contact, index: parseInt(this.$route.query.index) })
      Toast('修改成功')
      this.$router.go(-1)
    },
    onDelete () {
      alert('删除')
    }
  },
  components: {
    CommonHead
  }
}
</script>

<style lang="scss" scoped>
.wrap{
  margin-top: 46px;
}
</style>
